var t = new(require("../../../utils/http.js").HTTP);
Page({
  data: {
    previousPage: 1,
    total: 1,
    color:'#333',
    color1:'#666',
    text:''
  },
  onChangeColor(){
    this.setData({
      color:'#333',
      color1:'#666',
      text:'',
      previousPage:1,
      total:1
    })
    this.vacantRoom()
  },
  onChangeColor1(){
    this.setData({
      color:'#666',
      color1:'#333',
      text:this.data.user[1],
      previousPage:1,
      total:1
    })
    this.vacantRoom()
  },

  onSelect(event){
    var index = event.currentTarget.dataset.index;
    var tabs = this.data.xmgsList;
    let text = event.currentTarget.dataset.text
    for (var i = 0; i < tabs.length; i++) {
      if (i === index) {
        tabs[i].color = '#333';
      } else {
        tabs[i].color = '#666';
      }
    }
    this.setData({ xmgsList: tabs }); // 更新数据
    this.setData({
      text:text != '全部' ? text : '',
      previousPage:1,
      total:1
    })
    this.vacantRoom()
  },




  onLoad: function (t) {
    wx.setNavigationBarTitle({
      title: t.address,
      id: t.id
    });
    var a = wx.getStorageSync("user");
    let arr = a[7].split(',')
    arr.unshift('全部')
    arr = arr.map((item,index)=>{
      return Object.assign({
        text:item,
        color:index == 0 ? '#333' : '#666'
      })
    })
    this.setData({
        id: t.id,
        user: a,
        xmgsList:arr
      }),
      
      1 == t.id ? this.vacantRoom() : 2 == t.id ? this.rented() : 3 == t.id ? this.reserve() : this.rentOut()
  },
  vacantRoom: function () {
    var a = this;
    t.request({
      url: "https://www.qlsyyun.com:3030/lease/page",
      data: {
        arr: 1,
        zt:a.data.text
      }
    }).then((function (e) {
      a.setData({
          pageDown: e.data[0].num
        }),
        t.request({
          url: "https://www.qlsyyun.com:3030/lease",
          data: {
            arr: 1,
            total: a.data.total,
            zt:a.data.text
          }
        }).then((function (t) {
          a.setData({
            clients: t.data
          })
        }))
    }))
  },
  rented: function () {
    var a = this;
    a.data.user[4] > 6 ? t.request({
      url: "https://www.qlsyyun.com:3030/lease/page",
      data: {
        arr: 2
      }
    }).then((function (e) {
      a.setData({
          pageDown: e.data[0].num
        }),
        t.request({
          url: "https://www.qlsyyun.com:3030/lease",
          data: {
            arr: 2,
            total: a.data.total
          }
        }).then((function (t) {
          a.setData({
            customers: t.data
          })
        }))
    })) : t.request({
      url: "https://www.qlsyyun.com:3030/lease/page",
      data: {
        arr: 5,
        zhuti: a.data.user[1]
      }
    }).then((function (e) {
      a.setData({
          pageDown: e.data[0].num
        }),
        t.request({
          url: "https://www.qlsyyun.com:3030/lease",
          data: {
            arr: 5,
            total: a.data.total,
            zhuti: a.data.user[1]
          }
        }).then((function (t) {
          a.setData({
            customers: t.data
          })
        }))
    }))
  },
  reserve: function () {
    var a = this;
    t.request({
      url: "https://www.qlsyyun.com:3030/lease/page",
      data: {
        arr: 3
      }
    }).then((function (e) {
      a.setData({
          pageDown: e.data[0].num
        }),
        t.request({
          url: "https://www.qlsyyun.com:3030/lease",
          data: {
            arr: 3,
            total: a.data.total
          }
        }).then((function (t) {
          a.setData({
            customers: t.data
          })
        }))
    }))
  },
  rentOut: function () {
    var a = this;
    t.request({
      url: "https://www.qlsyyun.com:3030/lease/page",
      data: {
        arr: 4
      }
    }).then((function (e) {
      a.setData({
          pageDown: e.data[0].num
        }),
        t.request({
          url: "https://www.qlsyyun.com:3030/lease",
          data: {
            arr: 4,
            total: a.data.total
          }
        }).then((function (t) {
          a.setData({
            customers: t.data
          })
        }))
    }))
  },
  previousPage: function () {
    this.data.previousPage > 1 ? this.setData({
        total: this.data.total - 1,
        previousPage: this.data.total - 1
      }) : console.log("这是第一页"),
      1 == this.data.id ? this.vacantRoom() : 2 == this.data.id && this.rented(),
      wx.pageScrollTo({
        scrollTop: 0
      })
  },
  pageDown: function () {
    this.data.previousPage < this.data.pageDown && this.setData({
        total: this.data.total + 1,
        previousPage: this.data.total + 1
      }),
      1 == this.data.id ? this.vacantRoom() : 2 == this.data.id && this.rented(),
      wx.pageScrollTo({
        scrollTop: 0
      })
  },
  customer: function (t) {
    var a = t.currentTarget.dataset.id;
    wx.navigateTo({
      url: "/pages/record/search/search?id=" + a
    })
  },
  potential: function (t) {
    var a = t.currentTarget.dataset.id;
    1 != a && 2 != a || wx.navigateTo({
      url: "../vacantSearch/vacantSearch?id=" + a
    })
  },
  tailAfter: function (t) {
    var a = t.currentTarget.dataset.id;
    wx.navigateTo({
      url: "/pages/record/followSea/followSea?id=" + a
    })
  }
});